<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>消防进军训测试题</title>
    <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no,minimal-ui">
    <meta content="telephone=no" name="format-detection" />
    <meta content="email=no" name="format-detection" />

    <link rel="stylesheet" href="js/jquery-weui/dist/lib/weui.min.css">
    <link rel="stylesheet" href="js/jquery-weui/dist/css/jquery-weui.min.css">
    <link rel="stylesheet" href="css/app.css">

    <script src="js/jquery-weui/dist/lib/jquery-2.1.4.js"></script>
    <script src="js/jquery-weui/dist/js/jquery-weui.min.js"></script>
</head>
<body class="first-page">
<!--<div class="logo"><img src="imgs/logo.png" alt=""></div>-->

<form action="" novalidate method="post" class="login-form">
    <div class="weui-cells">
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <input class="weui-input" id="username" name="name" data-reg="" type="text" placeholder="请输入姓名">
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <input class="weui-input" id="phone" name="phone" data-reg="" type="text" placeholder="请输入手机号">
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <input class="weui-input" id="school" name="school" data-reg="" type="text" placeholder="请输入所在学校">
            </div>
        </div>
    </div>
    <a href="javascript:;" id="examBtn" class="weui-btn weui-btn_warn">开始答题</a>
    <div class="weui-footer">
        <a href="questions.html" class="weui-footer__text">跳过，直接进入答题</a>
    </div>

</form>
<script>

    $(document).ready(function(){
        window.localStorage.setItem('exam_form','');
        window.localStorage.setItem('exam_form_minute','');
        window.localStorage.setItem('exam_form_second','');

        //初始化页面
        Page.initPage();
    });
    var Page = {
        flag:0,
        /**
         * 初始化页面
         */
        initPage:function(){
            var self = this;
            $(document.body).on("touchmove", function (e) {
                //禁止触摸事件
                e.preventDefault();
            });
            self.initEvent();
        },
        /**
         * 初始化事件
         */
        initEvent:function(){
            var self = this;

            //开始答题按钮
            $("#examBtn").click(function() {
                var tel = $('#phone').val();
                var userName = $('#username').val();
                var school = $('#school').val();
                if(!userName){
                    $.toptip('请输入姓名','warning');
                }else if(!tel){
                    $.toptip('请输入手机号','warning')
                }else if(!school){
                    $.toptip('请输入所在学校','warning');
                }else if(!flag){
                    self.getUserInfo();
                }
            });
        },

        /**
         * 提交用户信息
         */
        getUserInfo:function(){
            var self = this;
            self.flag=1;

            //ajax提交用户信息
            var username    = $('#username').val();
            var phone       = $('#phone').val();
            var school      = $('#school').val();
            $.ajax({
                type: "post",
                async:false,
                url: "/login",
                dataType: "json",
                data:{'phone':phone,'username':username,'school':school},
                success: function(data) {
                    if(data.code == 0){
                        $.toptip(data.msg,'success');
                        setTimeout(function(){
                            location.href='/answer/details/';
                        },1000);
                        return false;
                    }else{
                        $.toptip(data.msg);
                        self.flag = 0;
                    }
                },
                error:function () {
                    self.flag = 0;
                    $.toptip('响应超时');
                }
            });
        }
    }


</script>
</body>
</html>